<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;
use think\Db;

/**
 * 文章类合并控制器
 */
class Bussiness extends AdminBase
{
    public $articleType = [
        1 =>"业务范围-GMP符合认证",
        2 =>"业务范围-国内注册",
        3 =>"业务范围-国际注册",
        4 =>"业务范围-MAH托管服务",
        5 =>"业务范围-药症事务顾问",
        6 =>"业务范围-会议&培训",
    ];
    
    
    
    /**
     * 国际gmp认证-新增
     */
    public function gmpIndex()
    {
        $this->commonList(1);
       
        return $this->fetch('article_list');
    }
    

    
    /**
     * 国内注册-编辑
     */
    public function cfdaEdit()
    {
        $this->commonList(2);
       
        return $this->fetch('article_list');
    }
    
    
    /**
     * 国际注册-编辑
     */
    public function fdaEdit()
    {
        $this->commonList(3);
       
        return $this->fetch('article_list');
    }
    
    
    /**
     * MAH托管服务-编辑
     */
    public function mahEdit()
    {
        $this->commonList(4);
       
        return $this->fetch('article_list');
    }
    
    
     /**
     * 会议&培训-编辑
     */
    public function meetingEdit()
    {
        $this->commonList(5);
       
        return $this->fetch('article_list');
    }
    
    
    /**
     * 药症事务顾问-编辑
     */
    public function medicientEdit()
    {
        $this->commonList(6);
       
        return $this->fetch('article_list');
    }
     
    
        
    /**
     * 通用文章列表获取方法
     * @param type $type 文章类型
     * @return type
     */
     public function commonList($type)
    {
         
        $where['pid'] = $type;
        
        $this->assign('list', $this->logicBussiness->getBussinessList($where, '*', 'sort,created_at desc'));
    }
  
    
    
    /**
     * 通用获取文章编辑信息
     * @param type $type 文章类型
     * @return type
     */
    public function articleEdit()
    {
       
        $this->articleCommon();

        if(empty($this->param['id'])){
            
            $article_id = $this->getIdByCategoryId($type);
            
        }else{
            
            $article_id = $this->param['id'];
        }

        $info = $this->logicBussiness->getArticleInfo(['id' => $article_id]);

        !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
        
        $this->assign('cate_list',$this->logicBussiness->getBussinessCategory([],'id,name,pid'));
        
        $this->assign('info', $info);
        
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 文章添加与编辑通用方法
     */
    public function articleCommon()
    {
        
        IS_POST && $this->jump($this->logicBussiness->bussinessEdit($this->param));
    }
    
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('Article', $this->param));
    }
    
    
    /**
     * 通过分类获取文章ID
     */
    public function getIdByCategoryId($type)
    {
        
        $article = Db::query('select id from rb_article where category_id=?',[$type]);
        
        $articleId = $article?$article[0]['id']:0;
        
        return $articleId;
    }
    
    
    /**
     * 添加业务范围分类
     */
    public function category()
    {
        $where['pid'] = array_key_exists('pid', $this->param)?$this->param['pid']:0;
          
        $this->assign('list', $this->logicBussiness->getBussinessCategory($where));
        
        return $this->fetch('category_list');
    }
    
    
    /**
     * 编辑业务范围分类
     */
    public function categoryEdit()
    {
        $this->assign('info',$this->logicBussiness->getCategoryInfo($this->param,'name,id,sort,pid'));
        
        $this->assign('cate_list',$this->logicBussiness->getBussinessCategory([],'id,name,pid'));
        
        return $this->fetch('category_edit');
    }
    
    
    /**
     * 添加业务范围分类
     */
    public function categoryAdd()
    {
        $this->categoryCommon();
        
        $this->assign('cate_list',$this->logicBussiness->getBussinessCategory([],'id,name'));
        
        $this->assign('info',[]);
        
        return $this->fetch('category_edit');
    }
    
    
     /**
     * 添加业务文章
     */
    public function bussinessAdd()
    {
        $this->bussinessCommon();
        
        $this->assign('cate_list',$this->logicBussiness->getBussinessCategory2([],'id,name'));
        
        return $this->fetch('article_edit');
    }
    
    
    /**
     * 分类编辑和添加通用方法
     */
    public function categoryCommon()
    {
        IS_POST && $this->jump($this->logicBussiness->bussinessCategoryEdit($this->param));
    }
    
    
    /**
     * 业务范围文章添加和编辑共用方法
     */
    public function bussinessCommon()
    {
        IS_POST && $this->jump($this->logicBussiness->bussinessEdit($this->param));
    }
    
    
    /**
     * 流程管理
     */
    public function processEdit()
    {
        $where['category_id'] = 24;
        
        IS_POST && $this->jump($this->logicArticle->ArticleEdit($this->param,$where['category_id'],'processedit'));
        
        $this->assign('info',$this->logicArticle->getStepInfo($where));
        
        
        return $this->fetch('process_edit');
    }
    
      /**
     * 排序
     */
    public function setSort()
    {
        
        $this->jump($this->logicAdminBase->setSort('Bussiness', $this->param));
    }
}
